<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:c="http://java.sun.com/jsp/jstl/core"
	xmlns:p="http://primefaces.org/ui" template="/templates/layout.xhtml">

	<ui:define name="ptitle">平台角色-权限管理</ui:define>
	<ui:define name="pcontent">
		<p:tabView id="tabview" >
		    <p:ajax event="tabChange" listener="#{sysRoleMB.onTabChange}" update=":tabview:frm2"/>	
			<p:tab id="tab1" title="角色维护">
				<h:form id="frm1">
					<p:growl id="msgs1" showDetail="true" />
					<p:panel id="resourcePanel" header="角色信息维护"
						style="margin-bottom:5px"
						footer="角色信息是可以作为权限分配的单元。一种角色可以包含一种或多种权限的组合。">
						<h:panelGrid columns="8" cellspacing="10">								
							<p:outputLabel value="角色ID" />
							<p:inputText  value="#{sysRoleMB.sysRole.id}" required="true" requiredMessage="角色编号必须输入"/>
							<p:outputLabel value="角色名称" />
							<p:inputText value="#{sysRoleMB.sysRole.name}" required="true" requiredMessage="角色名称必须输入"/>
							<p:outputLabel value="角色描述" />
							<p:inputText value="#{sysRoleMB.sysRole.description}" required="true" requiredMessage="角色描述必须输入"/>	
							<p:outputLabel value="角色状态" />
							<p:selectOneMenu value="#{sysRoleMB.sysRole.flag}"
								style="width:125px;" required="true" requiredMessage="角色状态必须输入">
								<f:selectItem  itemLabel="有效"	itemValue="1" />
								<f:selectItem  itemLabel="无效"	itemValue="0" />					
							</p:selectOneMenu>					
						</h:panelGrid>
						<h:panelGrid columns="4" cellspacing="10">			
							<p:commandButton value="新增角色提交"	icon="ui-icon-check" 
								action="#{sysRoleMB.addAction}" update=":tabview:frm1">
							</p:commandButton>	
						</h:panelGrid>
						<p:dataTable id="rdt" var="row" resizableColumns="true" liveResize="true" 
							value="#{sysRoleMB.voSysRole}" editable="true"
							style="margin-bottom:20px" >
							
							<p:ajax event="rowEdit" listener="#{sysRoleMB.onRowEdit}"
								update=":tabview:frm1:msgs1" />
							<p:ajax event="rowEditCancel"	listener="#{sysRoleMB.onRowCancel}"
								update=":tabview:frm1:msgs1" />

							<p:column headerText="角色ID" sortBy="#{row.id}">
								<p:cellEditor>
									<f:facet name="output">
										<h:outputText value="#{row.id}" />
									</f:facet>
									<f:facet name="input">
										<h:outputText id="modelInput" value="#{row.id}"
											style="width:100%" />
									</f:facet>
								</p:cellEditor>
							</p:column>
							<p:column headerText="角色名称">
								<p:cellEditor>
									<f:facet name="output">
										<h:outputText value="#{row.name}" />
									</f:facet>
									<f:facet name="input">
										<p:inputText value="#{row.name}" style="width:100%"
											label="角色名称" />
									</f:facet>
								</p:cellEditor>
							</p:column>
							<p:column headerText="角色描述">
								<p:cellEditor>
									<f:facet name="output">
										<h:outputText value="#{row.description}" />
									</f:facet>
									<f:facet name="input">
										<p:inputText value="#{row.description}" style="width:100%"
											label="角色描述" />
									</f:facet>
								</p:cellEditor>
							</p:column>
							<p:column headerText="角色状态">
								<p:cellEditor>
									<f:facet name="output">
										<h:outputText value="#{row.flag == 1 ? '有效' : (row.flag == 0 ? '无效' : row.flag)}" />
									</f:facet>
									<f:facet name="input">
										<p:selectOneMenu value="#{row.flag}" style="width:100%"
											required="true" requiredMessage="角色状态必须输入">
											<f:selectItem  itemLabel="有效"	itemValue="1" />
											<f:selectItem  itemLabel="无效"	itemValue="0" />					
										</p:selectOneMenu>										
									</f:facet>
								</p:cellEditor>
							</p:column>
							<p:column style="width:32px">
								<p:rowEditor />
							</p:column>
						</p:dataTable>

					</p:panel>
				</h:form>
				
			</p:tab>

			<p:tab id="tab2" title="角色权限管理">
				<h:form id="frm2">
					<p:growl id="msgs2" showDetail="true" />
					<p:panel id="rightsPanel" header="角色权限管理"
						style="margin-bottom:1px"
						footer="选定某个角色，选择要授予的权限，按下Ctrl键可以多选。点击授予选定权限按钮即可。">
						
						<h:outputText id="rolename" value="&nbsp;&nbsp;&nbsp;&nbsp;【当前选择的角色： #{sysRoleMB.rolename}】&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" style="font-size:16px;color:blue" />
						<p:commandButton value="授予选定权限" icon="ui-icon-check" action="#{sysRoleMB.authAction()}" update=":tabview:frm2:msgs2 :tabview:frm2:dtsetted">
							<p:confirm header="授权确认" message="确认授予该用户选定的权限?" icon="ui-icon-alert" />
						</p:commandButton>
						<p:commandButton value="回收选定权限" icon="ui-icon-trash" action="#{sysRoleMB.revokeAction()}" update=":tabview:frm2:msgs2 :tabview:frm2:dtsetted">
							<p:confirm header="回收确认" message="确认回收该用户选定的权限?" icon="ui-icon-alert" />
						</p:commandButton>			    
						
						<p:confirmDialog global="true" showEffect="fade" hideEffect="fade" width="200px" height="40px">
				        	<p:commandButton value="确认" type="button" styleClass="ui-confirmdialog-yes" icon="ui-icon-check" />
				        	<p:commandButton value="取消" type="button" styleClass="ui-confirmdialog-no" icon="ui-icon-close" />
				   		</p:confirmDialog>
				   		
					<h:panelGrid columns="2" cellspacing="20" >
		    		
					<p:dataTable id="dtrole" var="row"	value="#{sysRoleMB.voSysRole}" 
						selectionMode="single" selection="#{sysRoleMB.selectedRole}" rowKey="#{row.id}" 
						resizableColumns="true" liveResize="true" style="margin-bottom:1px;width:360px;" 
						scrollable="true" scrollHeight="120">					
						<f:facet name="header">角色信息</f:facet>
								
				        <p:ajax event="rowSelect" listener="#{sysRoleMB.onRoleRowSelect}" update=":tabview:frm2" />
				        <p:ajax event="rowUnselect" listener="#{sysRoleMB.onRoleRowUnselect}" update=":tabview:frm2:msgs2 :tabview:frm2:rolename" />
															
						<p:column headerText="角色ID" sortBy="#{row.id}">
							<h:outputText value="#{row.id}" />
						</p:column>	
						
						<p:column headerText="用户名称">
							<h:outputText value="#{row.name}" />
						</p:column>
										
					</p:dataTable>	
					
					<p:dataTable id="dtselection" var="arow"	value="#{sysRoleMB.voSelections}"
						selectionMode="multiple" selection="#{sysRoleMB.voSelected}" rowKey="#{arow.id}"
						resizableColumns="true" liveResize="true" style="margin-bottom:1px;width:360px;"
						scrollable="true" scrollHeight="122">					
						<f:facet name="header">可设置权限</f:facet>	
							
				        <p:ajax event="rowSelect" listener="#{sysRoleMB.onAuthRowSelect}" update=":tabview:frm2:msgs2 :tabview:frm2:dtselected" />
				        <p:ajax event="rowUnselect" listener="#{sysRoleMB.onAuthRowUnselect}" update=":tabview:frm2:msgs2 :tabview:frm2:dtselected" />
															
						<p:column headerText="权限ID" sortBy="#{arow.id}">
							<h:outputText value="#{arow.id}" />
						</p:column>	
						
						<p:column headerText="权限名称">
							<h:outputText value="#{arow.name}" />
						</p:column>
										
					</p:dataTable>				 
		
					<p:dataTable id="dtsetted" var="urow"	value="#{sysRoleMB.voSetted}"
						selectionMode="multiple" selection="#{sysRoleMB.voSelected}" rowKey="#{urow.id}"
						resizableColumns="true" liveResize="true" style="margin-bottom:1px;width:360px;"
						scrollable="true" scrollHeight="122">					
						<f:facet name="header">角色已有权限</f:facet>	
							
				        <p:ajax event="rowSelect" listener="#{sysRoleMB.onAuthoredRowSelect}" update=":tabview:frm2:msgs2 :tabview:frm2:dtselected" />
				        <p:ajax event="rowUnselect" listener="#{sysRoleMB.onAuthoredRowUnselect}" update=":tabview:frm2:msgs2 :tabview:frm2:dtselected" />
															
						<p:column headerText="权限ID" sortBy="#{urow.id}">
							<h:outputText value="#{urow.id}" />
						</p:column>	
						
						<p:column headerText="权限名称">
							<h:outputText value="#{urow.name}" />
						</p:column>
										
					</p:dataTable>				 
			 
					<p:dataTable id="dtselected" var="srow"	value="#{sysRoleMB.voSelected}"
						resizableColumns="true" liveResize="true" style="margin-bottom:1px;width:360px;"				
						scrollable="true" scrollHeight="122">					
						<f:facet name="header">已选择待设置权限</f:facet>		
															
						<p:column headerText="权限ID" sortBy="#{srow.id}">
							<h:outputText value="#{srow.id}" />
						</p:column>	
						
						<p:column headerText="权限名称">
							<h:outputText value="#{srow.name}" />
						</p:column>
										
					</p:dataTable>				 
					
					</h:panelGrid>
					
					</p:panel>
				</h:form>

			</p:tab>

		</p:tabView>
	</ui:define>
</ui:composition>

